package org.zjframework.traceframe.common.dao.util;

import java.sql.Connection; 
import java.sql.Statement; 
import java.sql.ResultSet; 
import java.sql.DriverManager; 
import java.sql.PreparedStatement; 
import java.sql.SQLException; 
public class InsertData { 
	
	/** Oracle��ݿ����� URL */
	private final static String DB_URL = "jdbc:mysql://localhost:3306/gxsbj";

	/** Oracle��ݿ������� */
	private final static String DB_DRIVER = "com.mysql.jdbc.Driver";

	/** ��ݿ��û��� */
	private final static String DB_USERNAME = "root";

	/** ��ݿ����� */
	private final static String DB_PASSWORD = "root";

        public static void main(String[] args){ 
                Connection myConnSDB = null; 
                PreparedStatement psInsertData=null; 
                int InsertData=0; 
                //Regist Oracle JDBC Driver 
                try { 
                        DriverManager.registerDriver(new com.mysql.jdbc.Driver()); 
                        myConnSDB= 
                                DriverManager.getConnection( 
                                        "DB_URL", 
                                        "DB_USERNAME", 
                                        "DB_PASSWORD"); 

                        myConnSDB.setAutoCommit(false); 

                } catch (SQLException e) { 
                        e.printStackTrace(); 
                } 

                try{ 
                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
                        Connection con = DriverManager.getConnection( "jdbc:odbc:Book1","","" ); 
                        Statement st = con.createStatement(); 
                        ResultSet rs = st.executeQuery( "SELECT * FROM [Sheet1$]" ); 
                        psInsertData= 
                                     myConnSDB.prepareStatement(" INSERT INTO TMP_TABLE"+ 
                                    " (ACTION_ID,TIMESTAMP,USERID,USERNAME,ISSUE,ACTION)"+ 
                                    "  VALUES "+ 
                                    " (?,?,?,?,?,?) ");  
                        while (rs.next()) { 
                                        psInsertData.clearParameters(); 
                                        psInsertData.setString(1,rs.getString(1)); 
                                        psInsertData.setString(2,rs.getString(2)); 
                                        psInsertData.setString(3,rs.getString(3)); 
                                        psInsertData.setString(4,rs.getString(4)); 
                                        psInsertData.setString(5,rs.getString(5)); 
                                        psInsertData.setString(6,rs.getString(6)); 
                                        InsertData=InsertData+psInsertData.executeUpdate();                                     

                        } 
                        System.out.println(""+InsertData); 
                        st.close(); 
                        con.close(); 
                }catch (Exception ex) 
           { 
                   System.err.print("Exception: "); 
                   System.err.println(ex.getMessage()); 
                   ex.printStackTrace(); 
           } finally 
                   { 
                         try 
                         { 
                                if (psInsertData!= null) 
                           { 
                                psInsertData.close(); 
                           } 
                                if (myConnSDB != null) 
                           { 
                                 myConnSDB.close(); 
                           } 
        
        
                         } catch (SQLException e) 
                         { 
                           e.printStackTrace(); 
                         } 
                   } 
                } 
        } 

